/**
 * Created by WangJunjie on 16/07/11.
 */
require.config(require_config);

define([
    'jquery',
    'common',
    'ready',
    'collection',
    'template',
    'model',
    'dialog',
    'datepicker'
], function ($, common, ready, Collection, template, Model, dialog, datepicker) {
    var index = function () {
        this.init();
    };
    index.prototype = {
        init: function () {
            loading();
            this.fetch();
            this.event();
        },

        fetch: function () {
            var _this = this;
            this.collection = new Collection({
                url: _global.url.api + 'wechatred/' + id,
                condition: {limit: 20, status: 'all'},  //查询条件
                model: {
                    url: _global.url.api + 'wechatred/' + id,
                    event: {}
                },
                callback: function () {
                    loaded();
                }
            });
            this.collection.fetch();
        },
        event: function () {
            this.data = {};
            var _this = this;
            //查询
            $('#btn-search').on('click', function (e) {
                e.preventDefault();
                _this.collection.condition.keyword = $('input[name="keyword"]').val();
                _this.collection.reload();
            });
            /**
             * 按状态查询
             */
            $('#btn-status').find('a').on('click', function (e) {
                e.preventDefault();
                $('input[name="keyword"]').val('');
                _this.collection.condition.keyword = '';
                _this.collection.condition.status = $(e.target).attr('rel');
                _this.collection.reload();
                $(e.target).addClass('active').siblings().removeClass('active');
            });

        }
    };

    new index();
});